/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.tnmk.worktime.gui.tbl;

import java.awt.Color;
import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JTable;
import org.apache.log4j.Logger;
import org.joda.time.DateTime;
import org.tnmk.worktime.utils.TimePeriodUtils;

/**
 *
 * @author Administrator
 */
public class WeekCellRenderer extends DecorateDefaultTableCellRenderer {
  private static final Logger log = Logger.getLogger(WeekCellRenderer.class.getSimpleName());
  @Override
  public Component getTableCellRendererComponent(JLabel comp, JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    if (isSelected) return comp;
    Object inTimeObj = table.getValueAt(row, 0);
    if (!(inTimeObj instanceof DateTime)){
      log.error("The first column must contain the InTime of WorkSession, so it must be an instance of DateTime. But current value is "+inTimeObj);
    }
    DateTime inTime = (DateTime)inTimeObj;
    if (TimePeriodUtils.isInThisWeek(inTime)){
//      Color bg = new Color(230, 235, 240);
//      Color fg = UIManager.getColor("Table.dropCellForeground");
      Color fg = new Color(60,70,80);
      comp.setForeground(fg);
    }else{
      Color fg = new Color(100, 100, 100);
      comp.setForeground(fg);
//      Color bg = Color.white;
//      comp.setBackground(bg);
    }
    return comp;
  }
}
